#!/bin/bash

# This is a simple script to download klines by given parameters.

# symbols=("BNBUSDT" "BTCUSDT") # add symbols here to download
# intervals=("1m" "3m" "5m" "15m" "30m" "1h" "2h" "4h" "6h" "8h" "12h" "1d" "3d" "1w" "1mo")
# years=("2017" "2018" "2019" "2020" "2021" "2022" "2023" "2024" "2025")


# symbols=('ETHUSDT'  'XRPUSDT'   'TRXUSDT'   'TONUSDT'   'EOSUSDT'   'SOLUSDT'   'CVXUSDT'   'ADAUSDT'   'DOGEUSDT'   'LINKUSDT'   'ARBUSDT'   'WETHUSDT'   'BTCUSDT'   'WBTCUSDT'   'WMATICUSDT'   'POLUSDT'   'MATICUSDT'   'BNBUSDT'   'WBNBUSDT'   'OKBUSDT'   'AVAXUSDT'   'AAVEUSDT'   'APTUSDT'   'DAOUSDT'   'DYDXUSDT'   '1INCHUSDT'   'MOVEUSDT'   'UNIUSDT'   'SUSHIUSDT'   'NMRUSDT')
symbols=('ETHUSDC'  'XRPUSDC'   'TRXUSDC'   'TONUSDC'   'EOSUSDC'   'SOLUSDC'   'CVXUSDC'   'ADAUSDC'   'DOGEUSDC'   'LINKUSDC'   'ARBUSDC'   'WETHUSDC'   'BTCUSDC'   'WBTCUSDC'   'WMATICUSDC'   'POLUSDC'   'MATICUSDC'   'BNBUSDC'   'WBNBUSDC'   'OKBUSDC'   'AVAXUSDC'   'AAVEUSDC'   'APTUSDC'   'DAOUSDC'   'DYDXUSDC'   '1INCHUSDC'   'MOVEUSDC'   'UNIUSDC'   'SUSHIUSDC'   'NMRUSDC')
intervals=("1m")
years=("2017" "2018" "2019" "2020" "2021" "2022" "2023" "2024" "2025")
years=("2022" "2023")

months=(01 02 03 04 05 06 07 08 09 10 11 12)

baseurl="https://data.binance.vision/data/spot/monthly/klines"

for symbol in ${symbols[@]}; do
  for interval in ${intervals[@]}; do
    for year in ${years[@]}; do
      for month in ${months[@]}; do
        url="${baseurl}/${symbol}/${interval}/${symbol}-${interval}-${year}-${month}.zip"
        response=$(wget --server-response -q ${url} 2>&1 | awk 'NR==1{print $2}')
        if [ ${response} == '404' ]; then
          echo "File not exist: ${url}" 
        else
          echo "downloaded: ${url}"
        fi
      done
    done
  done
done  
